package com.wechat.shopping.mall.config;


import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

//注解开启 swagger2 功能
@EnableSwagger2
//注解标示,这是一个配置类,@Configuation注解包含了@Component注解
//可以不用在使用@Component注解标记这是个bean了
@Configuration
public class SwaggerConfig {
	public static final String SWAGGER_SCAN_BASE_PACKAGE = "com.wechat.shopping.shopping.mall";
	public static final String VERSION = "1.0.0";

	@Bean
	public Docket createRestApi() {
		return new Docket(DocumentationType.SWAGGER_2)
				.apiInfo(apiInfo())
				.select()
				.apis(RequestHandlerSelectors.basePackage(SWAGGER_SCAN_BASE_PACKAGE))//api接口包扫描路径
				.paths(PathSelectors.any())//可以根据url路径设置哪些请求加入文档，忽略哪些请求
				.build();
	}
	private ApiInfo apiInfo() {
		return new ApiInfoBuilder()
				.title("微信购物程序-接口文档示例")//设置文档的标题
				.description("更多内容请关注：http://127.0.0.1:8888")//设置文档的描述->1.Overview
				.version(VERSION)//设置文档的版本信息-> 1.1 Version information
				.contact(new Contact("createBy wann", "", ""))//设置文档的联系方式->1.2 Contact information
				.build();
	}
}